package cn.clx.org.controller;

import cn.clx.basic.util.AjaxResult;
import cn.clx.basic.util.PageList;
import cn.clx.org.domain.DictionaryType;
import cn.clx.org.query.DictionaryTypeQuery;
import cn.clx.org.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionary")
public class DictionaryTypeController {

    @Autowired
    private IDictionaryTypeService DictionaryTypeService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping
    public List<DictionaryType> queryAll(){
        return DictionaryTypeService.queryAll();
    }

    /**
     * id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public DictionaryType queryById(@PathVariable("id") Long id){
        return DictionaryTypeService.queryById(id);
    }

    /**
     * 新增or修改
     * @param
     * @return
     */
    @PutMapping
    public AjaxResult updOrsave(@RequestBody DictionaryType dictionaryType){

        try {
            if(dictionaryType.getId()==null){
                DictionaryTypeService.save(dictionaryType);
            }else {
                DictionaryTypeService.update(dictionaryType);
            }
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("程序出错，殴打程序员中").setSuccess(false);
        }
    }
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){

        try {
            DictionaryTypeService.removeById(id);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("程序出错，殴打程序员中").setSuccess(false);
        }
    }
    @PostMapping
    public PageList<DictionaryType> queryPage(@RequestBody DictionaryTypeQuery query){
        return DictionaryTypeService.queryPage(query);
    }

/*    @PatchMapping
    public AjaxResult deleteList(@RequestBody DeptpartmentQuery query){
        try {
            DictionaryTypeService.deleteArray(query);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("程序错误,请殴打程序员");
        }

    }*/

}
